package com.usian.util.direct;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.usian.util.ConnectionUtil;

public class Send {
    public static void main(String[] args) throws Exception {
        // 获取到连接
        Connection connection = ConnectionUtil.getConnection();
        // 获取通道
        Channel channel = connection.createChannel();
        // 声明exchange，指定类型为direct
        channel.exchangeDeclare("rabbitmq-direct-exchange", "direct");
        // 消息内容
        String message = "insert";
        String message1 = "delete";
        String message2 = "update";
        // 发送消息，并且指定routing key 为：insert ,代表新增商品
        channel.basicPublish("rabbitmq-direct-exchange", "insert", null, message.getBytes());
        channel.basicPublish("rabbitmq-direct-exchange", "delete", null, message1.getBytes());
        channel.basicPublish("rabbitmq-direct-exchange", "update", null, message2.getBytes());
        System.out.println(" [商品服务：] Sent '" + message + "'");

        channel.close();
        connection.close();
    }
}
